package com.own.component.device.impl;

import com.own.component.device.base.RequestDeviceManager;
import com.own.component.device.property.DeviceProperty;

import javax.servlet.http.HttpServletRequest;

/**
 * DefaultCookieRequestDeviceManager
 *
 * @author chenxueli
 * @date 2024-03-15 11:35:47
 */
public class DefaultCookieRequestDeviceManager extends RequestDeviceManager {

    public DefaultCookieRequestDeviceManager(DeviceProperty property) {
        super(property);
    }

    /**
     * 获取客户端信息
     *
     * @return 客户端信息
     */
    @Override
    public String client(HttpServletRequest request) {
        if (request == null) {
            return null;
        }
        var cookies = request.getCookies();
        for (var cookie : cookies) {
            if (cookie.getName().equals(this.getDeviceIdField())) {
                return cookie.getValue();
            }
        }
        return null;
    }

}
